package com.test.daily.leetcode.y2022.m07.day0704.v03;

/**
 * @author Tom on 2022/7/4
 */
public class Solution {
    public int nearestIndex(int[] arr){
        if(arr == null || arr.length == 0){
            return -1;
        }
        int left = 0, right = arr.length - 1, mid = 0;
        while(left < right){
            mid = left + (right - left)/2;
            if(arr[mid] < arr[mid+1]){
                right = mid-1;
            } else if(arr[mid] > arr[mid+1]){
                left = mid+1;
            }else{
                return mid;
            }
        }
        return left;
    }
}
